package cn.linstudy.qo;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Description 封装数据结果集（某一页的数据）
 * @Author XiaoLin
 * @Date 2021/3/2 13:59
 */
@Data
public class PageResult<T> {
  private Integer currentPage;
  private Integer pageSize;

  private Integer totalCount;
  private List<T> data;

  private Integer prevPage;
  private Integer nextPage;
  private Integer totalPage;

  public PageResult(Integer currentPage, Integer pageSize, Integer totalCount, List<T> data) {
    this.currentPage = currentPage;
    this.pageSize = pageSize;
    this.totalCount = totalCount;
    this.data = data;
    this.totalPage = totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
    this.prevPage = currentPage - 1 >= 1 ? currentPage - 1 : 1;
    this.nextPage = currentPage + 1 <= totalPage ? currentPage + 1 : totalPage;
  }
}
